home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / pathfi1a / form1.frm next >
Text File  |  1999-09-04  |  10KB  |  352 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BackColor       =   &H00000000&
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   6210
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   7170
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   6210
  11.    ScaleWidth      =   7170
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.TextBox Text1 
  14.       BackColor       =   &H00000000&
  15.       ForeColor       =   &H00FFFFFF&
  16.       Height          =   285
  17.       Left            =   2040
  18.       TabIndex        =   7
  19.       Text            =   "200"
  20.       Top             =   5040
  21.       Width           =   975
  22.    End
  23.    Begin VB.Timer Timer2 
  24.       Enabled         =   0   'False
  25.       Interval        =   200
  26.       Left            =   2520
  27.       Top             =   5400
  28.    End
  29.    Begin VB.PictureBox picsrch 
  30.       AutoRedraw      =   -1  'True
  31.       AutoSize        =   -1  'True
  32.       Height          =   300
  33.       Left            =   1560
  34.       Picture         =   "Form1.frx":0000
  35.       ScaleHeight     =   240
  36.       ScaleWidth      =   240
  37.       TabIndex        =   6
  38.       Top             =   5520
  39.       Visible         =   0   'False
  40.       Width           =   300
  41.    End
  42.    Begin VB.PictureBox main 
  43.       AutoRedraw      =   -1  'True
  44.       AutoSize        =   -1  'True
  45.       Height          =   300
  46.       Index           =   1
  47.       Left            =   960
  48.       Picture         =   "Form1.frx":0342
  49.       ScaleHeight     =   240
  50.       ScaleWidth      =   240
  51.       TabIndex        =   4
  52.       Top             =   5520
  53.       Visible         =   0   'False
  54.       Width           =   300
  55.    End
  56.    Begin VB.Timer Timer1 
  57.       Interval        =   1
  58.       Left            =   3360
  59.       Top             =   5400
  60.    End
  61.    Begin VB.PictureBox buffer 
  62.       AutoRedraw      =   -1  'True
  63.       Height          =   4935
  64.       Left            =   5280
  65.       ScaleHeight     =   325
  66.       ScaleMode       =   3  'Pixel
  67.       ScaleWidth      =   361
  68.       TabIndex        =   1
  69.       Top             =   4080
  70.       Visible         =   0   'False
  71.       Width           =   5475
  72.    End
  73.    Begin VB.PictureBox main 
  74.       AutoRedraw      =   -1  'True
  75.       AutoSize        =   -1  'True
  76.       Height          =   300
  77.       Index           =   0
  78.       Left            =   600
  79.       Picture         =   "Form1.frx":0684
  80.       ScaleHeight     =   240
  81.       ScaleWidth      =   240
  82.       TabIndex        =   0
  83.       Top             =   5520
  84.       Visible         =   0   'False
  85.       Width           =   300
  86.    End
  87.    Begin VB.Label Label1 
  88.       AutoSize        =   -1  'True
  89.       BackStyle       =   0  'Transparent
  90.       Caption         =   "Change speed(milliseconds)"
  91.       ForeColor       =   &H00FFFFFF&
  92.       Height          =   195
  93.       Left            =   1560
  94.       TabIndex        =   8
  95.       Top             =   4800
  96.       Width           =   1965
  97.    End
  98.    Begin VB.Label pthfnd 
  99.       AutoSize        =   -1  'True
  100.       BackStyle       =   0  'Transparent
  101.       Caption         =   "Path Not Found"
  102.       ForeColor       =   &H00FFFFFF&
  103.       Height          =   195
  104.       Left            =   240
  105.       TabIndex        =   5
  106.       Top             =   5280
  107.       Width           =   1125
  108.    End
  109.    Begin VB.Label lbly 
  110.       AutoSize        =   -1  'True
  111.       BackStyle       =   0  'Transparent
  112.       Caption         =   "Y"
  113.       ForeColor       =   &H00FFFFFF&
  114.       Height          =   195
  115.       Left            =   120
  116.       TabIndex        =   3
  117.       Top             =   5040
  118.       Width           =   105
  119.    End
  120.    Begin VB.Label lblx 
  121.       AutoSize        =   -1  'True
  122.       BackStyle       =   0  'Transparent
  123.       Caption         =   "X"
  124.       ForeColor       =   &H00FFFFFF&
  125.       Height          =   195
  126.       Left            =   120
  127.       TabIndex        =   2
  128.       Top             =   4800
  129.       Width           =   105
  130.    End
  131. End
  132. Attribute VB_Name = "Form1"
  133. Attribute VB_GlobalNameSpace = False
  134. Attribute VB_Creatable = False
  135. Attribute VB_PredeclaredId = True
  136. Attribute VB_Exposed = False
  137. 'Written by Jonathon Lopez
  138. 'jjmlopez@flash.net
  139. Dim i As Integer, j As Integer, a As Integer, b As Integer, c As Variant, d As Variant, e As Variant, f As Variant, px As Variant, py As Variant, sqbufx As Integer, sqbufy As Integer, pos As Variant, found As Boolean, tries As Integer, try1 As Integer, direc As Integer
  140.  
  141. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  142. If X < 4841.12 And Y < 4841.12 Then 'if the mousedown was in the correct area then find path
  143.     a = (X \ 242.56)       'set the labels to hold the x,y values
  144.     b = (Y \ 242.56)
  145.     lblx = "X:" & a
  146.     lbly = "Y:" & b
  147.     ReDim d(0 To 19, 0 To 19) 'set up data for finding the path
  148.     ReDim e(0 To 19, 0 To 19)
  149.     ReDim f(0 To 19, 0 To 19)
  150.     ReDim px(0 To 19, 0 To 19)
  151.     ReDim py(0 To 19, 0 To 19)
  152.     For i = 0 To 19
  153.     For j = 0 To 19
  154.     d(i, j) = c(i, j)
  155.     e(i, j) = 0
  156.     f(i, j) = 0
  157.     py(i, j) = 0
  158.     Next j
  159.     Next i
  160.     found = False
  161.     e(pos(0, 0), pos(0, 1)) = 1
  162.     f(a, b) = 1
  163.     tries = 0
  164. top:
  165.     'the two following fors run whenever you click on the squares
  166.     'they basically do this:
  167.     'start with the goal square
  168.     'if the square next to me hasn't been reached yet then
  169.     'tell it that its been reached now
  170.     'and that it came from my direction(later, when the destination has been reached, it will use the direction data to retrace its steps)
  171.     'repeat for all sqaures until destination has been reached
  172.     For i = 0 To 19
  173.     For j = 0 To 19
  174.     If e(i, j) = 1 Then
  175.         On Error Resume Next
  176.         If d(i - 1, j) = 0 And e(i - 1, j) = 0 Then
  177.         e(i - 1, j) = 1
  178.         px(i - 1, j) = 1
  179.         py(i - 1, j) = j
  180.         End If
  181.         If d(i - 1, j - 1) = 0 And e(i - 1, j - 1) = 0 Then
  182.         e(i - 1, j - 1) = 1
  183.         px(i - 1, j - 1) = 2
  184.         py(i - 1, j - 1) = j
  185.         End If
  186.         If d(i - 1, j + 1) = 0 And e(i - 1, j + 1) = 0 Then
  187.         e(i - 1, j + 1) = 1
  188.         px(i - 1, j + 1) = 3
  189.         py(i - 1, j + 1) = j
  190.         End If
  191.         If d(i + 1, j) = 0 And e(i + 1, j) = 0 Then
  192.         e(i + 1, j) = 1
  193.         px(i + 1, j) = 4
  194.         py(i + 1, j) = j
  195.         End If
  196.         If d(i + 1, j - 1) = 0 And e(i + 1, j - 1) = 0 Then
  197.         e(i + 1, j - 1) = 1
  198.         px(i + 1, j - 1) = 5
  199.         py(i + 1, j - 1) = j
  200.         End If
  201.         If d(i + 1, j + 1) = 0 And e(i + 1, j + 1) = 0 Then
  202.         e(i + 1, j + 1) = 1
  203.         px(i + 1, j + 1) = 6
  204.         py(i + 1, j + 1) = j
  205.         End If
  206.         If d(i, j - 1) = 0 And e(i, j - 1) = 0 Then
  207.         e(i, j - 1) = 1
  208.         px(i, j - 1) = 7
  209.         py(i, j - 1) = j
  210.         End If
  211.         If d(i, j + 1) = 0 And e(i, j + 1) = 0 Then
  212.         e(i, j + 1) = 1
  213.         px(i, j + 1) = 8
  214.         py(i, j + 1) = j
  215.         End If
  216.     End If
  217.     tries = tries + 1
  218.     If e(a, b) = 1 Then
  219.     try1 = 0
  220.     found = True
  221.     pthfnd.Caption = "Path Found"
  222.     Call bitblt(Me.hDC, pos(0, 0) * 16, pos(0, 1) * 16, 16, 16, picsrch.hDC, 0, 0, SRCCOPY)
  223.     Call bitblt(Me.hDC, (a) * 16, (b) * 16, 16, 16, picsrch.hDC, 0, 0, SRCCOPY)
  224.     sqbufx = a
  225.     sqbufy = b
  226.     direc = 0
  227.     direc = px(a, b)
  228.     If direc = 1 Then sqbufx = sqbufx + 1
  229.     If direc = 2 Then
  230.     sqbufx = sqbufx + 1
  231.     sqbufy = sqbufy + 1
  232.     End If
  233.     If direc = 3 Then
  234.     sqbufx = sqbufx + 1
  235.     sqbufy = sqbufy - 1
  236.     End If
  237.     If direc = 4 Then sqbufx = sqbufx - 1
  238.     If direc = 5 Then
  239.     sqbufx = sqbufx - 1
  240.     sqbufy = sqbufy + 1
  241.     End If
  242.     If direc = 6 Then
  243.     sqbufx = sqbufx - 1
  244.     sqbufy = sqbufy - 1
  245.     End If
  246.     If direc = 7 Then sqbufy = sqbufy + 1
  247.     If direc = 8 Then sqbufy = sqbufy - 1
  248.     Timer2.Enabled = True
  249.     Exit Sub
  250.     End If
  251.     Next j
  252.     Next i
  253.      If tries > 3500 Then 'if there have been too many tries then stop
  254.     found = False
  255.     MsgBox "Path Not Found"
  256.     pthfnd.Caption = "Path Not Found"
  257.     Exit Sub
  258.     End If
  259.     If found = False Then GoTo top